using System;
using System.Collections.Generic;
using Volo.Abp.EventBus.Distributed;
using TenantManagementService.Monitoring;

namespace TenantManagementService.Events
{
    /// <summary>
    /// 告警触发事件
    /// </summary>
    public class AlertTriggeredEto : DistributedEto
    {
        /// <summary>
        /// 告警ID
        /// </summary>
        public Guid AlertId { get; set; }

        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 告警规则ID
        /// </summary>
        public Guid AlertRuleId { get; set; }

        /// <summary>
        /// 告警标题
        /// </summary>
        public string AlertTitle { get; set; } = string.Empty;

        /// <summary>
        /// 告警消息
        /// </summary>
        public string AlertMessage { get; set; } = string.Empty;

        /// <summary>
        /// 告警级别
        /// </summary>
        public AlertLevel AlertLevel { get; set; }

        /// <summary>
        /// 触发时的指标值
        /// </summary>
        public decimal TriggeredValue { get; set; }

        /// <summary>
        /// 指标名称
        /// </summary>
        public string MetricName { get; set; } = string.Empty;

        /// <summary>
        /// 阈值
        /// </summary>
        public decimal Threshold { get; set; }

        /// <summary>
        /// 操作符
        /// </summary>
        public string Operator { get; set; } = string.Empty;

        /// <summary>
        /// 告警规则名称
        /// </summary>
        public string AlertRuleName { get; set; } = string.Empty;

        /// <summary>
        /// 通知渠道
        /// </summary>
        public List<string> NotificationChannels { get; set; } = new();

        /// <summary>
        /// 触发时间
        /// </summary>
        public DateTime TriggeredAt { get; set; }

        /// <summary>
        /// 维度
        /// </summary>
        public Dictionary<string, string>? Dimensions { get; set; }
    }

    /// <summary>
    /// 告警解决事件
    /// </summary>
    public class AlertResolvedEto : DistributedEto
    {
        /// <summary>
        /// 告警ID
        /// </summary>
        public Guid AlertId { get; set; }

        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 告警标题
        /// </summary>
        public string AlertTitle { get; set; } = string.Empty;

        /// <summary>
        /// 告警级别
        /// </summary>
        public AlertLevel AlertLevel { get; set; }

        /// <summary>
        /// 持续时间（秒）
        /// </summary>
        public int Duration { get; set; }

        /// <summary>
        /// 处理人
        /// </summary>
        public string? HandledBy { get; set; }

        /// <summary>
        /// 处理备注
        /// </summary>
        public string? HandleNote { get; set; }

        /// <summary>
        /// 解决时间
        /// </summary>
        public DateTime ResolvedAt { get; set; }
    }

    /// <summary>
    /// 告警汇总事件
    /// </summary>
    public class AlertSummaryEto : DistributedEto
    {
        /// <summary>
        /// 汇总ID
        /// </summary>
        public Guid SummaryId { get; set; }

        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 总告警数
        /// </summary>
        public int TotalAlerts { get; set; }

        /// <summary>
        /// 严重告警数
        /// </summary>
        public int CriticalAlerts { get; set; }

        /// <summary>
        /// 紧急告警数
        /// </summary>
        public int EmergencyAlerts { get; set; }

        /// <summary>
        /// 警告告警数
        /// </summary>
        public int WarningAlerts { get; set; }

        /// <summary>
        /// 信息告警数
        /// </summary>
        public int InfoAlerts { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
    }

    /// <summary>
    /// 阈值警告事件
    /// </summary>
    public class ThresholdWarningEto : DistributedEto
    {
        /// <summary>
        /// 告警ID
        /// </summary>
        public Guid AlertId { get; set; }

        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 告警标题
        /// </summary>
        public string AlertTitle { get; set; } = string.Empty;

        /// <summary>
        /// 当前值
        /// </summary>
        public decimal CurrentValue { get; set; }

        /// <summary>
        /// 指标名称
        /// </summary>
        public string MetricName { get; set; } = string.Empty;

        /// <summary>
        /// 阈值
        /// </summary>
        public decimal Threshold { get; set; }

        /// <summary>
        /// 持续时间（秒）
        /// </summary>
        public int Duration { get; set; }

        /// <summary>
        /// 警告时间
        /// </summary>
        public DateTime WarningAt { get; set; }
    }

    /// <summary>
    /// 监控指标记录事件
    /// </summary>
    public class MetricRecordedEto : DistributedEto
    {
        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 指标名称
        /// </summary>
        public string MetricName { get; set; } = string.Empty;

        /// <summary>
        /// 指标值
        /// </summary>
        public decimal Value { get; set; }

        /// <summary>
        /// 时间戳
        /// </summary>
        public DateTime Timestamp { get; set; }

        /// <summary>
        /// 维度
        /// </summary>
        public Dictionary<string, string>? Dimensions { get; set; }

        /// <summary>
        /// 指标类型
        /// </summary>
        public MetricType MetricType { get; set; }

        /// <summary>
        /// 指标类别
        /// </summary>
        public MetricCategory MetricCategory { get; set; }
    }

    /// <summary>
    /// 系统健康状态变化事件
    /// </summary>
    public class SystemHealthChangedEto : DistributedEto
    {
        /// <summary>
        /// 健康状态
        /// </summary>
        public HealthStatus HealthStatus { get; set; }

        /// <summary>
        /// 组件状态
        /// </summary>
        public Dictionary<string, HealthStatus> ComponentStatus { get; set; } = new();

        /// <summary>
        /// 指标数据
        /// </summary>
        public Dictionary<string, object> Metrics { get; set; } = new();

        /// <summary>
        /// 问题列表
        /// </summary>
        public List<string> Issues { get; set; } = new();

        /// <summary>
        /// 检查时间
        /// </summary>
        public DateTime CheckTime { get; set; }

        /// <summary>
        /// 前一次健康状态
        /// </summary>
        public HealthStatus? PreviousHealthStatus { get; set; }
    }

    /// <summary>
    /// 租户资源使用量告警事件
    /// </summary>
    public class TenantResourceUsageAlertEto : DistributedEto
    {
        /// <summary>
        /// 租户ID
        /// </summary>
        public Guid TenantId { get; set; }

        /// <summary>
        /// 租户名称
        /// </summary>
        public string TenantName { get; set; } = string.Empty;

        /// <summary>
        /// 资源类型（users, storage, api）
        /// </summary>
        public string ResourceType { get; set; } = string.Empty;

        /// <summary>
        /// 当前使用量
        /// </summary>
        public long CurrentUsage { get; set; }

        /// <summary>
        /// 最大限制
        /// </summary>
        public long MaxLimit { get; set; }

        /// <summary>
        /// 使用率（百分比）
        /// </summary>
        public double UsagePercentage { get; set; }

        /// <summary>
        /// 告警级别
        /// </summary>
        public AlertLevel AlertLevel { get; set; }

        /// <summary>
        /// 告警时间
        /// </summary>
        public DateTime AlertTime { get; set; }
    }
}